<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>红包管理</title>
<load href="__PUBLIC__/css/bootstrap.min.css" />
<import type='css' file="css.main" />
<load href="__PUBLIC__/js/jquery-1.9.1.min.js" />
<load href="__PUBLIC__/js/jquery-ui.min.js" />
<script type="text/javascript" src="/IndexPublic/js/jquery.form.js"></script>
<style type="text/css">
.main-frame{border: none;}
.infos{position:relative;}
.infosf *{display: block; float: left;}
.obj-form li .infosf input{width: 60px; padding:6px 12px;}
.obj-form li .infosf form{position: absolute; opacity:0;}
.obj-form li .infosf .infos a{height: 32px; line-height: 22px;}

form.form2{display: block; position: absolute; right: 12px; top: 70px; width:360px; height: 500px;}
ul.ul{display:block; clear:both; border:solid 1px #eee; border-radius:5px; width: 100%; height: 480px; list-style:none; margin:0px; padding:0px; overflow:auto; overflow-x:hidden;}
ul.ul span{display: block; padding: 10px; overflow: hidden;}
ul.ul li{clear:none; float:none; padding:0px; margin:0px; display:block; float:left; width:150px; overflow:hidden; height:24px; line-height:24px; margin-right:6px;}
div.pushhead{border-bottom:solid 1px #eee; clear:both; margin-bottom:0px; height: 36px; line-height: 36px; background-color: #383e4c; padding: 0px 12px; color: #fff;}
input.tjiao{display: block; clear: both; width: 150px; margin: 0px auto; margin-top: 12px; background-color: #383e4c; list-style: none; color: #fff; font-size: 14px; border: none; height: 32px; line-height: 28px; border-radius: 3px;}
.btninfo input{display: block; float: left; clear: inherit; margin-right: 12px;}
.obj-form li.submit .btninfo .submitbtn{clear: inherit; background-color: #999;}
.obj-form li.submit .btninfo .test{background-color: #ff5454;}
</style>
</head>

<body id="body">
<div class="main-frame">
	<div class="position">华人码 > 账号管理 > 红包接口</div>
	<div class="addobject">
		<div class="obj-form">
			<form name="form1" id="form1" action="{:U('hbinfoadd')}" method="post" class="form-inline">
				<input type="hidden" name="status" value="{$hbinfo.status}" />
				<ul>
					<li class="lititle">
						<label class="fl tle">APPID：</label>
						<span class="fl cnt">
						<input name="u_appid" type="password" class="form-control" placeholder="APPID" value="{$hbinfo.u_appid}"><em>*</em>
						</span>
					</li>
					<li class="lititle">
						<label class="fl tle">APPSECRET：</label>
						<span class="fl cnt">
						<input name="u_appsecret" type="password" class="form-control" placeholder="APPSECRET" value="{$hbinfo.u_appsecret}"><em>*</em>
						</span>
					</li>
					<li class="hktinfo">
						<label class="fl tle">商户ID：</label>
						<span class="fl cnt">
						<input name="u_merchantid" type="password" class="form-control" placeholder="商户ID" value="{$hbinfo.u_merchantid}"><em>*</em>
						</span>
					</li>
					<li class="hktinfo">
						<label class="fl tle">微信支付秘钥：</label>
						<span class="fl cnt">
						<input name="u_paykey" type="password" class="form-control" placeholder="微信支付秘钥" value="{$hbinfo.u_paykey}"><em>*</em>
						</span>
					</li>
					<li>
						<label class="fl tle">授权证书1：</label>
						<span class="fl cnt infosf">
							<input name="u_cert" readonly class="form-control" placeholder="授权证书1" value="{$hbinfo.u_cert}" style="width: 400px;">
							<div class="infos">
								<a class="browse" f='u_cert'>浏览···</a>
								<input accept="*/*" id="u_cert" type="file" name="uu_cert" style="margin-left: 10px; opacity:0; position: absolute;" /> <em>&nbsp;&nbsp;*(此处上传名为：apiclient_cert.pem 的文件)</em>
							</div>
						</span>
					</li>
					<li>
						<label class="fl tle">授权证书2：</label>
						<span class="fl cnt infosf">
							<input name="u_key" readonly class="form-control" placeholder="授权证书2" value="{$hbinfo.u_key}" style="width: 400px;">
							<div class="infos">
								<a class="browse" f='u_cert'>浏览···</a>
								<input accept="*/*" id="u_key" type="file" name="uu_key" style="margin-left: 10px; opacity:0; position: absolute;" /> <em>&nbsp;&nbsp;*(此处上传名为：apiclient_key.pem 的文件)</em>
							</div>
						</span>
					</li>
					<!--<li class="hktinfo">-->
						<!--<label class="fl tle">红包范围：</label>-->
						<!--<span class="fl cnt">-->
						<!--<input name="u_hbmin" type="text" class="form-control" placeholder="如：1" value="{$hbinfo.u_hbmin}" style="width: 80px;"> - -->
						<!--<input name="u_hbmax" type="text" class="form-control" placeholder="如：200" value="{$hbinfo.u_hbmax}" style="width: 80px;"><em>* 红包范围必须是1-200元</em>-->
						<!--</span>-->
					<!--</li>-->
					<if condition="$hbinfo['status'] neq 1">
						<li class="submit">
							<label class="fl tle">&nbsp;</label>
							<span class="fl cnt btninfo">
								<input type="button" value="测试一下" class="submitbtn test" id="test" />
								<input type="submit" value="保 存" class="submitbtn" id="btnsave" disabled="disabled" />
							</span>
						</li>
					<else />
						<li class="submit">
							<label class="fl tle">&nbsp;</label>
						    <span class="fl cnt" style="color: #38f;">此红包接口有效，如需修改请联系管理员</span>
						</li>
					</if>
				</ul>
			</form>
		</div>
		<div class="obj-previewimg">
			<div class="instructions">
				<b>操作说明：</b><br>
				1、带有红色  “ * ” 项必填<br>
			</div>
		</div>
	</div>

</div>


<script type="text/javascript">
	$(function () {
		$("#test").click(function(){
			var u_appid = $("input[name='u_appid']").val();
			var u_merchantid = $("input[name='u_merchantid']").val();
			var u_paykey = $("input[name='u_paykey']").val();
			var u_cert = '{:C('WEBDOMAIN')}'+$("input[name='u_cert']").val();
			var u_key = '{:C('WEBDOMAIN')}'+$("input[name='u_key']").val();
			var confirms = '{$md5confirm}';
			var getdata_url = "http://pay.hrtv.cn/hongbao/sendredpack";
			var data = {"re_openid":'o4BL8s0_1cX8NaNq8JrR4E2KZAO4',"act_name":'Test',"send_name":'Test',"remark":'Test',"wishing":'Test',"confirm":confirms,"appid":u_appid,"mchid":u_merchantid,"partnerkey":u_paykey,"clientcert":u_cert,"clientkey":u_key,'rand':Math.random()};
			$.ajax({
				url:getdata_url,
				data:data,
				type:"GET",
				dataType:"JSON",
				success:function (val){
//					writeObj(val);
//					return false;
					if(val['statuss']==1 || val['info']=="系统错误:帐号余额不足，请到商户平台充值后再重试"){
						alert('连接成功');
						$("input[name='status']").val(1);
						$("#btnsave").removeAttr('disabled');
						$("#btnsave").css({"background-color":"#ff5454"});
						$("#test").attr('disabled','disabled');
						$("#test").css({"background-color":"#999"});
						$("form[name='form1']").submit();
					}else{
						alert('连接失败');
					}
				},
				error:function(val){
					alert('连接失败');
				}
			});
		})

		upfile('u_cert','idname1');
		upfile('u_key','idname2');
		function upfile(obj,name){
			$("#"+obj).wrap("<form id='"+name+"' name='"+name+"' action='/Admin/User/up/pra/"+obj+"' method='post' enctype='multipart/form-data'></form>");
			$("#"+obj).change(function(){
				$("#"+name).ajaxSubmit({
					dataType:  'json',
					beforeSend: function() {
					},
					uploadProgress: function(event, position, total, percentComplete) {
					},
					success: function(result) {
						if(result==1){
							chstatus();
							alert('文件格式不正确');
						}else if(result==0){
							alert('上传失败');
						}
					},
					error:function(xhr){
						var result = xhr.responseText;
						if(result==0){
							alert('上传失败');
						}else if(result==2){
							alert('超出限定范围30M');
						}else if(result==3){
							alert('请选择要上传的视频文件');
						}else{
							if(xhr.status=='404'){
								alert('大小超出限定范围30M');
							}else{
								//result //返回文件路径
								$("input[name='"+obj+"']").val(result);
								//return false;
							}

						}

					}
				});
			});
		}


		function writeObj(obj){
			var description = "";
			for(var i in obj){
				var property=obj[i];
				description+=i+" = "+property+"\n";
			}
			alert(description);
		}



	});
</script>
</body>
</html>
